import React, { useEffect, useState, useRef } from 'react';
//3 useRef:获取DOM元素  只能在函数组件中用【所有的ReactHook函数,都只能在函数组件中用，在类组件中会报错】

export default function CaseThree() {
  const [num, setNum] = useState(0);
  let box = useRef(null);
  const handle = () => {
    setNum(num + 1);
  };
  useEffect(() => {
    console.log(box.current);
  }, []);
  return (
    <>
      <div className='demo'>
        <span className='num' ref={box}>
          {num}
        </span>
        <button onClick={handle}>新增</button>
      </div>
    </>
  );
}
